<!-- 项目评估 -->
<!-- powerType 为1是只读,为2是可编辑 -->
<template>
  <div class="app-container">
    <Edialog
      ref="Edialog"
      :outershow="outershow"
      :title="title"
      @saveFn="saveFn"
      @close="closeFn"
      :saveClick="finishFirst ? true : false"
      :width="finishFirst ? '70%' : '20%'"
    >
      <el-row :gutter="20" v-loading="loading" v-if="finishFirst">
        <el-row :gutter="20">
          <el-form
            :model="timeObj"
            ref="timeObj"
            label-width="100px"
            class="edit-form"
          >
            <el-row :gutter="20">
              <el-col :span="22">
                <el-form-item label="评估年份" prop="startTime">
                  <span
                    >{{ timeObj.startTime || "--" }} ~
                    {{ timeObj.endTime || "--" }}</span
                  >
                </el-form-item>
              </el-col>
              <!-- <el-col :span="11">
                <div style="font-size: 14px">
                  <el-form-item label="结束年份" prop="endTime">
                    <span>{{ timeObj.endTime }}</span>
                  </el-form-item>
                </div>
              </el-col> -->
            </el-row>
          </el-form>
        </el-row>

        <el-col :span="24">
          <!-- 获取计算结果 -->
          <el-button
            @click="getCalculationResult"
            type="primary"
            size="small"
            style="margin-bottom: 10px"
            :loading="btnLoading"
          >
            刷新结果
          </el-button>
          <SpreadSheet
            v-loading="sheetLoading"
            v-if="outershow"
            style="height: 55vh; width: 100%"
            ref="Sheet"
            SheetName="Sheet1"
            :File="file"
            :ColumnWidth="200"
            :Records="records"
            @loaded="loaded"
            @cell-selected="cellSelected"
            @change="sheetChange"
            @cell-edited="cellEdited"
          ></SpreadSheet>
          <el-radio-group
            v-model="tabPosition"
            style="margin-top: 20px"
            size="small"
          >
            <el-radio-button
              :label="item.templateName"
              v-for="item in dynamicsTemplateData"
              :key="item.id"
              @click.native="changeSceneTemplate(item)"
              >{{
                item.templateCode + "-" + item.templateName || "模板名称"
              }}</el-radio-button
            >
          </el-radio-group>
        </el-col>
      </el-row>
      <el-row v-else :gutter="20">
        <el-form
          :rules="TimeRules"
          :model="timeObj"
          ref="timeRef"
          label-width="100px"
          class="btns-item"
        >
          <el-form-item label="开始年份" prop="startTime">
            <el-date-picker
              v-model="timeObj.startTime"
              type="year"
              value-format="yyyy"
              placeholder="开始年份"
            >
            </el-date-picker
          ></el-form-item>

          <el-form-item label="结束年份" prop="endTime">
            <el-date-picker
              v-model="timeObj.endTime"
              type="year"
              value-format="yyyy"
              placeholder="结束年份"
            >
            </el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button @click="nextStepFn" type="primary">下 一 步</el-button>
            <el-button @click="outershow = false">取 消</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </Edialog>
    <subject_choose
      v-if="isShowDialog"
      @close="closeDialog"
      @successFn="successFn"
      ref="subject_choose"
    ></subject_choose>
  </div>
</template>

<script>
import {
  indexToCoord,
  getNonEmptyMergedCells,
  updateCellAttributesByCondition,
  findChangedCells,
  updateCellAttributes,
  coordToIndex,
  findCellsByPowerType,
  updateStyleAttributes,
} from "@/utils/spreadsheet.js";
import { fd } from "@/utils";
import SpreadSheet from "@/components/Xspreadsheet/SpreadSheet.vue";
import Edialog from "@/components/Edialog/indexLoading.vue";
import subject_choose from "@/components/Xspreadsheet/subject_choose.vue";
import {
  ProjectEvalInfoDynamicsTemplateApi,
  putProjectEvalInfoApi,
  ProjectEvalInfoReflushValuesApi,
  ProjectEvalInfoPerviewValuesApi,
  ProjectEvalInfoDeleteApi,
} from "@/api/projectManage";
export default {
  data() {
    return {
      btnLoading: false,
      //先完成第一个日期弹窗的填写
      finishFirst: false,
      timeObj: {
        startTime: "",
        endTime: "",
      },
      tabPosition: "",

      TimeRules: {
        startTime: [
          { required: true, message: "开始年份不能为空", trigger: "blur" },
        ],
        endTime: [
          {
            required: false,
            message: "结束年份不能为空",
            trigger: "blur",
          },
          { validator: this.validateEndYear, trigger: "blur" },
        ],
      },

      isShowDialog: false,
      tableData: [],
      loading: false,
      file: null,
      ColumnCount: 30,
      RowCount: 100,
      headers: [],
      records: [],
      outershow: false,
      title: "项目评估",
      type: "",
      sheetLoading: false,
      openData: {},
      dynamicsTemplateData: [],
      //传给后端用
      uuid: "",
      workbookData: [],
      cellEditArr: [],
      currentItem: {},
    };
  },
  components: {
    Edialog,
    SpreadSheet,
    subject_choose,
  },
  methods: {
    validateEndYear(rule, value, callback) {
      if (parseInt(value, 10) < parseInt(this.timeObj.startTime, 10)) {
        callback(new Error("结束年份不能小于开始年份"));
      } else {
        callback();
      }
    },
    nextStepFn() {
      this.cellEditArr = [];
      this.$refs.timeRef.validate(async (valid) => {
        if (valid) {
          this.finishFirst = true;
          let params = {
            startTime: this.timeObj.startTime,
            endTime: this.timeObj.endTime,
            projectCode: this.openData.projectCode,
          };
          let res = await ProjectEvalInfoDynamicsTemplateApi(params);
          if (res.data && res.data.bcode == 0) {
            this.dynamicsTemplateData = res.data.bdata.models;
            this.uuid = res.data.bdata.uuid;
            if (this.dynamicsTemplateData.length > 0) {
              //处理dataType,为1表示未编辑过，为2表示编辑过
              this.dynamicsTemplateData.forEach((data) => {
                if (data.subjectList && data.subjectList.length > 0) {
                  data.subjectList.forEach((item) => {
                    item.dataType = 1; //默认都为1,编辑后变为2
                  });
                  // 首先解析一次 JSON，避免在循环中重复解析
                  let parsedExcelJson = JSON.parse(data.excelJson);

                  data.subjectList.forEach((x, index) => {
                    if (x.subjectCode) {
                      let { rowIndex, colIndex } = coordToIndex(x.subjectCode);
                      // 给动态生成的cell添加style属性
                      // 使用当前 styles 的长度作为新的样式索引，同步更新json中的styles数组，这样后面赋值样式才能生效
                      x.style = parsedExcelJson[0].styles.length;
                      // 更新样式属性，传入解析后的JSON对象
                      parsedExcelJson = updateStyleAttributes(
                        parsedExcelJson[0].styles.length,
                        {
                          border: {
                            top: ["thin", "#000000"],
                            bottom: ["thin", "#000000"],
                            left: ["thin", "#000000"],
                            right: ["thin", "#000000"],
                          },
                          //黄色
                          bgcolor: x.powerType == 2 ? "#ffff00" : "#ffffff",
                          textwrap: true,
                          // color: "#900b09",
                          align: "center",
                          valign: "middle",
                          border: {
                            top: ["thin", "#1E1E1E"],
                            bottom: ["thin", "#1E1E1E"],
                            right: ["thin", "#1E1E1E"],
                            left: ["thin", "#1E1E1E"],
                          },
                          font: {
                            bold: false,
                          },
                        },
                        parsedExcelJson
                      );
                      // 更新单元格属性
                      parsedExcelJson = updateCellAttributes(
                        rowIndex,
                        colIndex,
                        {
                          style: x.style,
                        },
                        parsedExcelJson
                      );
                    }
                  });
                  // 最后，将更新后的JSON对象重新赋值给data.excelJson
                  data.excelJson = JSON.stringify(parsedExcelJson);
                }
              });
              // console.log(
              //   "this.dynamicsTemplateData",
              //   JSON.parse(
              //     this.$cloneDeep(this.dynamicsTemplateData[0].excelJson)
              //   )
              // );
              this.tabPosition = this.dynamicsTemplateData[0].templateName;
              let updatedExcelJson = JSON.parse(
                this.$cloneDeep(this.dynamicsTemplateData[0].excelJson)
              );
              //updatedExcelJson:根据powerType == 1加上editable属性的json 用于在场景编辑时预览
              this.$set(
                this.dynamicsTemplateData[0],
                "updatedExcelJson",
                JSON.stringify(
                  updateCellAttributesByCondition(
                    updatedExcelJson,
                    "editable",
                    false,
                    (cell) => cell.powerType == "1"
                  )
                )
              );
              //用于后面比对发生变化的源数组
              this.$set(
                this.dynamicsTemplateData[0],
                "updatedExcelJsonSource",
                JSON.stringify(
                  updateCellAttributesByCondition(
                    updatedExcelJson,
                    "editable",
                    false,
                    (cell) => cell.powerType == "1"
                  )
                )
              );
              this.$nextTick(async () => {
                await this.changeSceneTemplate(this.dynamicsTemplateData[0]);
                this.getCalculationResult();
              });
            }
          }
        }
      });
    },

    async changeSceneTemplate(item) {
      this.currentItem = item;
      this.sheetLoading = true;
      //当有cellEditArry时，先计算结果
      if (this.cellEditArr.length > 0) {
        console.log("先计算结果");
        await this.getCalculationResult();
      }

      //获取单条预览模板结果值
      // let res = await ProjectEvalInfoPerviewValuesApi({
      //   templateId: item.id,
      //   endTime: this.timeObj.endTime,
      //   startTime: this.timeObj.startTime,
      //   projectId: this.openData.id,
      //   uuid: this.uuid,
      // });
      // console.log(2);
      // if (res.data && res.data.bcode == 0) {
      // let  changeItem = res.data.bdata;
      //   console.log("changeItem", changeItem, this.dynamicsTemplateData);
      // }
      // ===============================以下为拼接json重要逻辑===================================
      // let updatedExcelJson = JSON.parse(this.$cloneDeep(item.excelJson));
      // //updatedExcelJson:根据powerType == 1加上editable属性的json 用于在场景编辑时预览
      // this.$set(
      //   item,
      //   "updatedExcelJson",
      //   JSON.stringify(
      //     updateCellAttributesByCondition(
      //       updatedExcelJson,
      //       "editable",
      //       false,
      //       (cell) => cell.powerType == "1"
      //     )
      //   )
      // );
      // //用于后面比对发生变化的源数组
      // this.$set(
      //   item,
      //   "updatedExcelJsonSource",
      //   JSON.stringify(
      //     updateCellAttributesByCondition(
      //       updatedExcelJson,
      //       "editable",
      //       false,
      //       (cell) => cell.powerType == "1"
      //     )
      //   )
      // );
      // if (item.subjectList && item.subjectList.length > 0) {
      //   //静态数组
      //   let valueList = [];
      //   //动态数组
      //   let dyvalueList = [];
      //   item.subjectList.forEach((x, index) => {
      //     if (x.isDynamic == 1) {
      //       dyvalueList.push(x);
      //     } else {
      //       valueList.push(x);
      //     }
      //     let { rowIndex, colIndex } = coordToIndex(x.subjectCode);
      //     let excelJson = this.$cloneDeep(item.updatedExcelJson);
      //     //给动态生成的cell添加style属性
      //     x.style = JSON.parse(excelJson)[0].styles.length + index;
      //     item.updatedExcelJson = JSON.stringify(
      //       updateCellAttributes(
      //         rowIndex,
      //         colIndex,
      //         {
      //           dataType: x.dataType,
      //           address: x.subjectCode,
      //           text: x.textValue || x.subjectSign,
      //           result: x.textValue,
      //           formula:
      //             x.subjectCodeFormula == "null"
      //               ? ""
      //               : x.subjectCodeFormula || "",
      //           subjectCodeFormula: x.subjectCodeFormula,
      //           subjectSign: x.subjectSign,
      //           subjectCode: x.subjectCode,
      //           originalSubjectCode: x.originalSubjectCode,
      //           subjectCodeSort: x.subjectCodeSort,
      //           isDynamic: x.isDynamic,
      //           powerType: x.powerType,
      //           // style: x.style,
      //           editable: x.powerType == 1 ? false : true,
      //         },
      //         JSON.parse(excelJson)
      //       )
      //     );
      //=======================================以上为拼接json重要逻辑===================================
      //尾巴括号
      // });

      this.$nextTick(async () => {
        console.log(
          "可编辑单元格加入黄色背景nextTick",
          JSON.parse(item.updatedExcelJson)
        );
        let itemUpdatedExcelJson = this.$cloneDeep(item.updatedExcelJson);
        //用于后面比对发生变化的源数组（拼接好数据的json在项目管理里面才是当前的原数组，场景管理同理）
        this.$set(item, "updatedExcelJsonSource", itemUpdatedExcelJson);
        this.$refs.Sheet.loadData(JSON.parse(item.updatedExcelJson) || []);
      });

      setTimeout(() => {
        console.log(
          "可编辑单元格加入黄色背景setTimeout"
          // JSON.parse(item.updatedExcelJson),
          // xs.datas[0].styles
        );
        //可编辑单元格加入黄色背景
        let editableCell = findCellsByPowerType(
          JSON.parse(item.updatedExcelJson),
          2
        );
        if (editableCell.length > 0) {
          editableCell.forEach((e) => {
            // console.log("e.subjectCode", e.subjectCode, e);
            let { rowIndex, colIndex } = coordToIndex(
              e.subjectCode || e.address
            );
            let cell = xs.sheet.data.getCell(rowIndex, colIndex);
            xs.datas.forEach((row) => {
              this.$set(row.styles, cell.style, {
                border: {
                  top: ["thin", "#000000"],
                  bottom: ["thin", "#000000"],
                  left: ["thin", "#000000"],
                  right: ["thin", "#000000"],
                },
                //黄色
                bgcolor: "#ffff00",
                textwrap: true,
                // color: "#900b09",
                align: "center",
                valign: "middle",
                border: {
                  top: ["thin", "#1E1E1E"],
                  bottom: ["thin", "#1E1E1E"],
                  right: ["thin", "#1E1E1E"],
                  left: ["thin", "#1E1E1E"],
                },
                font: {
                  bold: false,
                },
              });
              xs.reRender();
            });
            // }
          });
        }
        this.sheetLoading = false;
      }, 500);
      //尾巴括号
      // }
    },
    successFn(e) {
      console.log("选择成功", e);
    },
    closeDialog() {
      this.isShowDialog = false;
    },
    templatechooseFn() {
      this.isShowDialog = true;
      this.$nextTick(() => {
        this.$refs.subject_choose.manufacturerOpen();
      });
    },

    cellSelected(cell, ri, ci) {
      // console.log("cellSelected", cell, ri, ci);
    },
    sheetChange(data) {
      // console.log("sheetChange", data);
      this.cellEditArr.push(1);
      this.dynamicsTemplateData.forEach((item) => {
        if (item.templateName == this.tabPosition) {
          let ChangedCells =
            findChangedCells(JSON.parse(item.updatedExcelJsonSource), data) ||
            [];
          console.log("修改的单元格", ChangedCells, item);
          if (ChangedCells.length > 0) {
            ChangedCells.forEach((cell) => {
              //因为如果复制会导致单元格里面的所有属性都被复制，所以这里只修改text属性
              let { rowIndex, colIndex } = coordToIndex(
                cell.originalCell.address
              );
              let excelJson = this.$cloneDeep(item.updatedExcelJson);
              item.updatedExcelJson = JSON.stringify(
                updateCellAttributes(
                  rowIndex,
                  colIndex,
                  {
                    text: cell.updatedCell.text || "",
                    result: cell.updatedCell.text || "",
                    address: cell.originalCell.address,
                    subjectCode: cell.originalCell.address,
                    dataType: 2,
                  },
                  JSON.parse(excelJson)
                )
              );
            });
          }
        }
      });
      // 注释掉解决只能改一个单元格的问题，因为每次修改都会触发这个方法，所以每次修改都会把之前修改的值覆盖掉
      // this.dynamicsTemplateData.forEach((item) => {
      //   if (item.templateName == this.tabPosition) {
      //     item.updatedExcelJson = JSON.stringify(data);
      //   }
      // });
    },
    cellEdited(cell, ri, ci) {
      //用于判断用户是否手动点击更新数据按钮
      //让修改同步到要提交的excelJson中,要提交的excelJson是没有根据powerType == 1加上editable属性的json(原本是这样)
      // this.cellEditArr.push(1);
      // this.dynamicsTemplateData.forEach((item) => {
      //   if (item.templateName == this.tabPosition) {
      //     console.log("cellEdited", cell);
      //     let excelJson = this.$cloneDeep(item.updatedExcelJson);
      //     item.updatedExcelJson = JSON.stringify(
      //       updateCellAttributes(
      //         ri,
      //         ci,
      //         {
      //           text: cell.text || "",
      //           result: cell.text || "",
      //           address: indexToCoord(ri, ci),
      //           subjectCode: indexToCoord(ri, ci),
      //           dataType: 2,
      //         },
      //         JSON.parse(excelJson)
      //       )
      //     );
      //     item.subjectList.forEach((subject) => {
      //       if (subject.subjectCode == indexToCoord(ri, ci)) {
      //         subject.result = "xxxxxxx" || cell.text || "";
      //         subject.dataType = 2;
      //       }
      //     });
      //   }
      // });
      // console.log("cellEdited", cell, ri, ci);
    },
    //表格数据加载事件
    loaded(workbookData) {
      console.log("loaded", workbookData);
    },
    //外部打开弹窗
    openFn(data) {
      console.log("open", data);
      this.timeObj = {
        startTime: "",
        endTime: "",
      };
      this.openData = data; //项目信息,id为项目id
      this.finishFirst = false;
      this.outershow = true;
    },
    //处理保存接口和预览结果接口参数
    getParams() {
      let evalTemplateList = [];
      console.log("this.dynamicsTemplateData", this.dynamicsTemplateData);
      this.dynamicsTemplateData.forEach((item) => {
        if (item && item.updatedExcelJson) {
          console.log(
            "JSON.parse(item.updatedExcelJson)",
            JSON.parse(item.updatedExcelJson)
          );
          const changedCells = findChangedCells(
            JSON.parse(item.updatedExcelJsonSource),
            JSON.parse(item.updatedExcelJson)
          );
          console.log("changedCells", changedCells);
          let valueList = [];
          let dyvalueList = [];
          changedCells.forEach((cell) => {
            if (cell.updatedCell.isDynamic == 1) {
              dyvalueList.push({
                subjectSign: cell.updatedCell.subjectSign,
                sort: cell.updatedCell.subjectCodeSort,
                subjectCode: cell.updatedCell.originalSubjectCode,
                dataType: cell.updatedCell.dataType,
                //2025.08.07改动,项目评估这里编辑的值要是把原先编辑的值删了的话。你这边就传的值是空的给我，页面自己带出场景值展示。接口可以不用给我。后端自己会判断获取。
                // result: cell.updatedCell.result
                //   ? cell.updatedCell.result
                //   : cell.updatedCell.sceneTextValue || "",
                result: cell.updatedCell.result ? cell.updatedCell.result : "",
              });
            } else if (cell.updatedCell.isDynamic == 0) {
              valueList.push({
                subjectCode:
                  cell.updatedCell.subjectCode || cell.updatedCell.address,
                // subjectSign: cell.updatedCell.subjectSign,
                dataType: cell.updatedCell.dataType,
                //2025.08.07改动,项目评估这里编辑的值要是把原先编辑的值删了的话。你这边就传的值是空的给我，页面自己带出场景值展示。接口可以不用给我。后端自己会判断获取。
                // result: cell.updatedCell.result
                //   ? cell.updatedCell.result
                //   : cell.updatedCell.sceneTextValue || "",
                result: cell.updatedCell.result ? cell.updatedCell.result : "",
              });
            }
          });
          let list = [...valueList, ...dyvalueList];
          let filteredArray = [];
          if (list.length > 0) {
            // 使用 filter 筛选出 dataType 为 2 的元素
            filteredArray = list.filter((item) => item.dataType == 2);
            console.log("filteredArray", filteredArray);
          }
          evalTemplateList.push({
            valueList: filteredArray || [],
            // dyvalueList: dyvalueList,
            templateId: item.id,
            excelJson: item.updatedExcelJson,
          });
          console.log("入参excelJson", JSON.parse(item.updatedExcelJson));
        }
      });
      console.log("evalTemplateList", evalTemplateList);
      // return;
      return {
        sceneId: this.sceneId,
        evalTemplateList: evalTemplateList,
        endTime: this.timeObj.endTime,
        startTime: this.timeObj.startTime,
        projectId: this.openData.id,
        uuid: this.uuid,
      };
    },
    async getCalculationResult() {
      this.btnLoading = true;
      console.log(1, "刷新结果");
      //点击按钮后清空cellEditArr
      this.cellEditArr = [];
      let { uuid, sceneId, evalTemplateList, endTime, startTime, projectId } =
        this.getParams();

      // return;
      let params = {
        uuid,
        sceneId,
        evalTemplateList,
        endTime,
        startTime,
        projectId,
      };
      console.log("过滤后");

      params.evalTemplateList = params.evalTemplateList.filter((item) => {
        // 删除不需要的字段
        delete item.excelJson;
        // 保留的条件：valueList存在、是数组、数组不为空
        return (
          item.valueList &&
          Array.isArray(item.valueList) &&
          item.valueList.length > 0
        );
      });

      console.log("过滤后的数组", params.evalTemplateList);

      //调用刷新结果接口
      let res = await ProjectEvalInfoReflushValuesApi(params);
      this.btnLoading = false;
      if (res.data && res.data.bcode == 0) {
        let data = res.data.bdata;
        console.log("刷新结果获取数组", data, this.dynamicsTemplateData);
        // 获取到所有模板的新单元格值 逐个替换旧值
        this.dynamicsTemplateData.forEach((item) => {
          data.forEach((x) => {
            if (item.templateCode == x.sheetName) {
              x.values.forEach((x1) => {
                item.subjectList.forEach((item1) => {
                  if (x1.subjectCode == item1.subjectCode) {
                    item1.textValue = x1.textValue;
                  }
                });
              });
            }
          });
          console.log("a", item);
          let updatedExcelJson;
          if (item.updatedExcelJson) {
            updatedExcelJson = JSON.parse(
              this.$cloneDeep(item.updatedExcelJson)
            );
          } else {
            updatedExcelJson = JSON.parse(this.$cloneDeep(item.excelJson));
          }
          //updatedExcelJson:根据powerType == 1加上editable属性的json 用于在场景编辑时预览
          this.$set(
            item,
            "updatedExcelJson",
            JSON.stringify(
              updateCellAttributesByCondition(
                updatedExcelJson,
                "editable",
                false,
                (cell) => cell.powerType == "1"
              )
            )
          );
          //用于后面比对发生变化的源数组
          this.$set(
            item,
            "updatedExcelJsonSource",
            JSON.stringify(
              updateCellAttributesByCondition(
                updatedExcelJson,
                "editable",
                false,
                (cell) => cell.powerType == "1"
              )
            )
          );
          if (item.subjectList && item.subjectList.length > 0) {
            console.log("拼接item", item);
            item.subjectList.forEach((x, index) => {
              if (x.subjectCode) {
                let { rowIndex, colIndex } = coordToIndex(x.subjectCode);
                let excelJson = this.$cloneDeep(item.updatedExcelJson);
                item.updatedExcelJson = JSON.stringify(
                  updateCellAttributes(
                    rowIndex,
                    colIndex,
                    {
                      dataType: x.dataType,
                      address: x.subjectCode,
                      //2025.08.07改动 项目评估：界面结果值显示改下：如果单元格结果没有值。直接空显示；不用默认显示科目值；
                      text: x.textValue || "",
                      // text: x.textValue || x.subjectSign,
                      result: x.textValue,
                      formula:
                        x.subjectCodeFormula == "null"
                          ? ""
                          : x.subjectCodeFormula || "",
                      subjectCodeFormula: x.subjectCodeFormula,
                      subjectSign: x.subjectSign,
                      subjectCode: x.subjectCode,
                      originalSubjectCode: x.originalSubjectCode,
                      subjectCodeSort: x.subjectCodeSort,
                      isDynamic: x.isDynamic,
                      powerType: x.powerType,
                      sceneTextValue: x.sceneTextValue,
                      // style: x.powerType == 1 ? 0 : "",
                      editable: x.powerType == 1 ? false : true,
                    },
                    JSON.parse(excelJson)
                  )
                );
              }
            });
            console.log("b");
          }
          setTimeout(() => {
            if (item.templateCode == this.currentItem.templateCode) {
              this.changeSceneTemplate(item);
              console.log("c");
            }
          });
        });
      }
    },
    async saveFn() {
      //当有cellEditArry时，先计算结果
      if (this.cellEditArr.length > 0) {
        console.log("先计算结果");
        await this.getCalculationResult();
      }
      let params = this.getParams();
      params.evalTemplateList.forEach((item) => {
        delete item.dyvalueList;
        delete item.valueList; //删除 valueList,dyvalueList,保存数据不需要
      });
      await putProjectEvalInfoApi(params).then((res) => {
        if (res.data && res.data.bcode == 0) {
          this.$message.success("保存成功");
          this.closeFn();
          this.$emit("refreshFn");
        }
      });
      setTimeout(() => {
        this.$refs.Edialog.closeLoading();
      }, 500);
    },
    async closeFn() {
      //关闭弹窗调用接口清除后端缓存
      let { uuid, sceneId, evalTemplateList, endTime, startTime, projectId } =
        this.getParams();
      await ProjectEvalInfoDeleteApi({
        uuid: uuid,
        startTime: startTime,
        endTime: endTime,
        projectId: projectId,
      }).then((res) => {
        if (res.data && res.data.bcode == 0) {
          console.log("清除后端缓存成功");
        }
      });
      this.outershow = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-select {
  width: 100%;
}
.el-form-item {
  width: 45%;
  // display: flex;
}
.edit-form {
  .el-form-item {
    width: 45%;
    // display: flex;
    margin-bottom: 0px;
  }
}
.btns-item {
  ::v-deep .el-form-item {
    width: 100%;
  }
}
::v-deep .el-form-item__content {
  width: 60% !important;
}
.ellipsis_text {
  width: 200px; /* 或者你希望的固定宽度 */
  white-space: nowrap; /* 防止文本换行 */
  overflow: hidden; /* 隐藏超出容器的文本 */
  text-overflow: ellipsis; /* 使用省略号表示超出容器的文本 */
}
</style>
